package com.ponhu.ea2.goodsCenter.provider.factory;

import org.springframework.stereotype.Component;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * @author luyu
 * @create 2021-11-02 21:01
 */
@Component
public class GoodsFactory {

    private static Map<Class, GoodsFactoryService> shapeMap = new HashMap<>();

    public static void setMap(GoodsFactoryService createGoodsFactoryService) {

        Class aClass = (Class) ((ParameterizedTypeImpl) createGoodsFactoryService.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0];

        shapeMap.put(aClass, createGoodsFactoryService);
    }

    public static GoodsFactoryService getShape(Class clazz) {
        GoodsFactoryService createGoodsFactoryService = shapeMap.get(clazz);
        return createGoodsFactoryService;
    }

}
